var _inherit = require('core/inherit.js');
var _vec3f = require('core/glm.js').vec3f;

var TWEEN = require('third_party/tweenjs/tween.js');

// ==========================
// Fragment
// ==========================
function Fragment(container, view) {
    this.mContainer = container;
    this.mView = view;
    this.mPosition = new _vec3f();

    this.x = 0;
    this.y = 0;
}
/**
 * create tween animation
 * @param from
 * @returns {*}
 */
Fragment.prototype.tween = function (from) {
    for (var i in from) {
        this[i] = from[i];
    }
    return new TWEEN.Tween(this).onUpdate(this.onUpdate);
};
Fragment.prototype.getView = function () {
    return this.mView;
};
Fragment.prototype.setPosition = function (x, y) {
    this.mPosition.set(x, y);
    this.mContainer.getSize().mul(this.mPosition, this.mView.getPosition());
    this.mView.touchMatrix();
};
Fragment.prototype.onUpdate = function () {
    this.setPosition(this.x, this.y);
};
/**
 * remove from parent
 */
Fragment.prototype.remove = function () {
    this.mContainer.removeFragment(this);
    this.mContainer = null;
    this.mView = null;
};
Fragment.prototype.resize = function () {
    this.mView.setSize(this.mContainer.getSize());
};

module.exports = Fragment;